package com.meitianhui.convenitenbuy.module.store.adapter;

import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.meitianhui.convenitenbuy.Constants;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.store.model.CouponCardInfo;
import com.meitianhui.convenitenbuy.util.GlideUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/28.
 */

public class PreferentialActivityAdapter extends BaseQuickAdapter<CouponCardInfo.Coupon,BaseViewHolder> {
    private Map<String,String> mUrlMap;

    public PreferentialActivityAdapter(@Nullable List<CouponCardInfo.Coupon> data) {
        super(R.layout.item_preferential_coupon, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CouponCardInfo.Coupon item) {
        RelativeLayout rlCoupon = helper.getView(R.id.rl_coupon);
        RelativeLayout rlRecord = helper.getView(R.id.rl_record);
        ImageView ivSaleOut = helper.getView(R.id.iv_sale_out);
        TextView tvType = helper.getView(R.id.tv_type);
        TextView tvName = helper.getView(R.id.tv_name);
        switch (item.Type){
            case 0:
                rlCoupon.setVisibility(View.VISIBLE);
                rlRecord.setVisibility(View.GONE);
                Integer num = Integer.parseInt(item.getUsable_num());
                Log.i("num------剩余", num + "");
                if (num <= 0) {//灵光
                    ivSaleOut.setVisibility(View.VISIBLE);
                } else {
                    ivSaleOut.setVisibility(View.GONE);
                }
                if (item.getCategory_id().equals(Constants.CONS_CASH)) {
                    rlCoupon.setBackgroundResource(R.mipmap.icon_preferential_coupon_bg);
                    tvType.setText("现\n金\n购\n买");
                    tvName.setText(item.getTitle());

                } else if (item.getCategory_id().equals(Constants.CONS_FREE)) {
                    rlCoupon.setBackgroundResource(R.mipmap.icon_preferential_coupon_bg_green);
                    tvType.setText("免\n费\n领\n取");
                    tvName.setText(item.getTitle());

                }
                helper.setText(R.id.tv_date,"截止日期:" + item.getExpired_date().substring(0, 10));
                helper.setText(R.id.tv_sale,"已售:" + item.getUsed_num());
                break;

            case 1:
                rlCoupon.setVisibility(View.GONE);
                rlRecord.setVisibility(View.VISIBLE);
                helper.setText(R.id.tv_content,item.getTitle());
                String path = mUrlMap.get(item.getPath_id());
                GlideUtils.setRectImage(mContext,path,R.mipmap.icon_default_picture,R.mipmap.icon_default_picture,helper.getView(R.id.iv_path));
                break;


        }

    }

    public void setNewData(List data, Map<String, String> map) {
        setNewData(data);
        this.mUrlMap = map;
    }
}
